<?php
namespace Home\Controller;
use Think\Controller;
//登陆控制器
class LoginController extends Controller{
	//注册方法
	public function register(){
		
		
		
	}
	
	//登陆方法
	public function login(){
		if(IS_POST){
			
			$password=$_POST['passwd'];
			$username=$_POST['username'];
			$data=M('User')->where(array('username'=>$username))->find();
			if(!$data){
				$this->error("用户名错误");
			}else if(md5($password)!=$data['password']){
				$this->error("对不起，密码错误");
			}
			$code=$_POST['code'];
			$bool=$this->check_verify($code);
			if(!$bool){
			    $this->error("对不起，您输入的验证码有误！",U('Login/login'));
			}
			
			session('username',$username);
			$this->error("登录成功",U('Index/index'));
		}
		$this->display();
	}
	
	//验证码
	Public function verify(){
			$config =    array(
		    'fontSize'    =>    20,    // 验证码字体大小
		    'length'      =>    1,     // 验证码位数
		    'useNoise'    =>    false, // 关闭验证码杂点
		    'imageW'      =>120,
			);
		    $Verify = new \Think\Verify($config);
			$Verify->codeSet = '0123456789'; 
//			$Verify->useImgBg = true; 
    		$Verify->entry();
	}
	
	function check_verify($code, $id = ''){
    $verify = new \Think\Verify();
    return $verify->check($code, $id);
	}

}
?>